//
//  SJPDepartmentView.m
//  SWS_Project00
//
//  Created by 马继鵬 on 17/3/8.
//  Copyright © 2017年 SWS. All rights reserved.
//

#import "SJPDepartmentView.h"
#import "SJPDepartmentController.h"

@interface SJPDepartmentView()
@property (weak,nonatomic) UIView* topView;
@end
@implementation SJPDepartmentView


- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        [self setupUI];
    }
    return self;
}

#pragma
#pragma-设置UI
- (void)setupUI
{
    [self setupView];
    [self setupCollectionController];
    
    
    
    
}
#pragma
#pragma-添加"名医通"视图
- (void)setupView{
    UIView* topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.width, 40)];
    [self addSubview:topView];
    topView.backgroundColor = [UIColor whiteColor];
    _topView = topView;
    
    //设置绿条
    UIImageView* imageView = [[UIImageView alloc]init];
    [topView addSubview:imageView];
    imageView.image = [UIImage imageNamed:@"nav"];
    //位置设置
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.offset(17);
        make.height.mas_equalTo(27);
        make.centerY.offset(0);
        make.width.mas_equalTo(10);
    }];
    imageView.layer.cornerRadius = 5;
    imageView.layer.masksToBounds = YES;
    
    //添加Label
    UILabel* label = [UILabel EPM_labelWithTitle:@"名医通" textColor:[UIColor blackColor] font:20];
    [topView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.leading.equalTo(imageView.mas_trailing).offset(17);
    }];
}

#pragma
#pragma-添加"名医通"控制器
- (void)setupCollectionController
{
    //设置布局
    UICollectionViewFlowLayout* layout = [[UICollectionViewFlowLayout alloc]init];
    //cell布局设置
    CGFloat width = (self.width - 4)/3;
    CGFloat height = (self.height - 44)/2;
    layout.itemSize = CGSizeMake(width, height);
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.minimumLineSpacing = 1;
    layout.minimumInteritemSpacing = 1;
    layout.sectionInset = UIEdgeInsetsMake(1, 1, 1, 1);

    
    //添加controller
    SJPDepartmentController* controller = [[SJPDepartmentController alloc]initWithCollectionViewLayout:layout];
    
    [self addSubview: controller.collectionView];
    self.childContrller = controller;
    
    
    [controller.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topView.mas_bottom).offset(0);
        make.leading.trailing.bottom.offset(0);
        
        
    }];
    
}

@end
